﻿<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl" %>

<script type="text/javascript">
    var appendixsetting = {
        check: {
            enable: true
        },
        data: {
            simpleData: {
                enable: true
            }
        },
        callback: {
            onCheck: appendixCheck
        }
    };


    var treeObj;
    var usernode;

    $(function intityUserTree_MsgSend() {
        $.ajax({
            url: "/Home/getUserTree",
            type: "POST",
            success: function(userNodes) {
                setting.callback.onCheck = onUsertreeCheck_MsgPartial;
                $.fn.zTree.init($("#msg_tree"), setting, eval(userNodes));
                usernode = userNodes;
            }
        });
    });

    function appendixCheck(e, treeId, treeNode) {
        addAppendix();
    }

    function showAppendix() {
        var appendixNode = $("#appendixNode").val();
        $("#appendix").fadeIn("slow");
        $.fn.zTree.init($("#msg_tree"), appendixsetting, eval(appendixNode));
    }

    function addAppendix() {
        var treeObj = $.fn.zTree.getZTreeObj("msg_tree");
        var nodes = treeObj.getCheckedNodes(true);
        var appendixName = "";
        var appendix = "";

        for (var index = 0; index < nodes.length; index++) {
            if (nodes[index].id == "appendix")
                continue;
            appendixName += nodes[index].name + " ";
            appendix += nodes[index].id + ";";
        }
        $("#appendixName").html(appendixName);
        $("#appendixHi").val(appendix);
//        $("#appendix").fadeOut("slow");
//        $.fn.zTree.init($("#msg_tree"), setting, eval(usernode));
    }

    function cancel() {
        $("#appendix").fadeOut("slow");
        $.fn.zTree.init($("#msg_tree"), setting, eval(usernode));
    }

    function submit() {
        var title = $("#msgtitle").val();
        var content = $("#msgcontent").val();
        var receiver_ids = $("#receiver_ids").val();
        var creater_id = $("#creater_id").val();
        var appendixs = $("#appendixHi").val();
        if (receiver_ids.length == 0) {
            alert("请选择收件人");
            return false;
        }
        if (title == "") {
            alert("请填写标题");
            return;
        }
        $.ajax({
            url: "/Message/DoSendMsg",
            type: "POST",
            data: { "title": title, "content": content, "receiver_ids": receiver_ids, "creater_id": creater_id, "appendix": appendixs },
            success: function(data) {
                alert(data);
                MsgShowOrHide();
            }
        });
    }

    function onUsertreeCheck_MsgPartial(event, treeId, treeNode) {
        //alert(treeNode.id + ", " + treeNode.name + "," + treeNode.checked);
        var treeObj = $.fn.zTree.getZTreeObj("msg_tree");
        var nodes = treeObj.getCheckedNodes(true);
        var temp_name = "";
        var temp_id = "";
        for (i = 0; i < nodes.length; i++) {
            temp_id = temp_id + nodes[i].id + ",";
            temp_name = temp_name + nodes[i].name + ",";
        }
        $("#receiver_ids").attr("value", temp_id);
        $("#receiver_names").attr("value", temp_name);
    };

</script>

<div id="facebox" style="top: 25.8px; left: 354.5px;">
    <div class="popup">
        <table>
            <tbody>
                <tr>
                    <td class="tl">
                    </td>
                    <td class="b">
                    </td>
                    <td class="tr">
                    </td>
                </tr>
                <tr>
                    <td class="b">
                    </td>
                    <td class="body">
                        <div class="content" style="display: block;">
                            <div id="messages">
                                <!-- Messages are shown when a link with these attributes are clicked: href="#messages" rel="modal"  -->
                                <%=Html.Hidden("creater_id", ViewData["creater_id"]) %>
                                <%=Html.Hidden("receiver_ids") %>
                                <div id="msg_top">
                                    <h3 style="width: 300px;">
                                        <%=ViewData["msg_numb"].ToString() %>
                                        Messages</h3>
                                    <a style="position: absolute; top: 14px; right: 18px;" href="#">
                                        <img src="../../images/msg_close.png" onclick="MsgShowOrHide()" /></a>
                                </div>
                                <div id="msg_left" style="float: left; width: 350px;">
                                    <div id="msg_content" style="padding-top: 10px; min-height: 150px; padding: 15px 25px 5px 0;">
                                        <div style="border: 1px solid #808080; height: 170px; margin-top: 10px;">
                                            <%using (System.Data.DataTable dt = ViewData["dt"] as System.Data.DataTable)
                                              {
                                                  for (int i = 0; i < dt.Rows.Count; i++)
                                                  {
                                            %>
                                            <p>
                                                <strong>
                                                    <%=dt.Rows[i]["发送时间"].ToString() %></strong> by
                                                <%=dt.Rows[i]["发起人"].ToString() %><br />
                                                <%=dt.Rows[i]["内容"].ToString() %>
                                            </p>
                                            <%}
                                              } %>
                                        </div>
                                    </div>
                                    <h4>
                                        New Message</h4>
                                    <fieldset>
                                        标题
                                        <input type="text" id="msgtitle " style="margin-left: 5px; margin-bottom: 5px;" />
                                        <textarea id="msgcontent" class="textarea" name="textfield" cols="79" rows="8" style="height: 100px;
                                            margin-top: 5px;"></textarea>
                                    </fieldset>
                                    <fieldset>
                                        <%--      <select name="dropdown" class="small-input">
                                            <option value="option1">Send to...</option>
                                            <option value="option2">Everyone</option>
                                            <option value="option3">Admin</option>
                                            <option value="option4">Jane Doe</option>
                                        </select>--%>
                                        <div>
                                            <div id="appendixName" style="width: 325px; height: 20px; border: solid 1px gray;">
                                            </div>
                                        </div>
                                        <br />
                                        <input class="button" type="submit" value="Send" onclick="return submit(); " />
                                    </fieldset>
                                </div>
                                <div id="msg_right" style="float: right; width: 230px; padding-right: 10px; padding-top: 15px;">
                                    <input type="button" onclick="showAppendix();" value="附件列表" style="margin-top: 5px;" />
                                    <input type="button" onclick="cancel()" value="用户列表" />
                                    <!--选择树-->
                                    <div id="div_tree" class="zTreeDemoBackground left" style="float: left; width: 230px;
                                        margin-top: 0px;">
                                        <ul id="msg_tree" class="ztree">
                                        </ul>
                                        <div class="divBox" id="appendix" style="display: none;">
                                            <input type="hidden" id="appendixNode" value="<%=ViewData["appendix"] %>" />
                                            <input id="appendixHi" type="hidden" /><br />
                                            <%--    <input type="button" onclick="addAppendix();" value="确定" />--%>
                                        </div>
                                    </div>
                                </div>
                            </div>
                            <div class="footer" style="display: block;">
                            </div>
                    </td>
                    <td class="b">
                    </td>
                </tr>
                <tr>
                    <td class="bl">
                    </td>
                    <td class="b">
                    </td>
                    <td class="br">
                    </td>
                </tr>
            </tbody>
        </table>
    </div>
</div>
